<?php
class Default_Model_TourChat extends Zend_Db_Table{

	protected $_name = TOUR_CHAT_TABLE;
	protected $_primary = 'tour_chat_id';

	private $TOUR_CHAT_ID = 'tour_chat_id';
	private $TOUR_ID = 'tour_id';
	private $USER_ID = 'user_id';

	protected $db;

	public function __construct(){
		//Goi ket noi voi Zend Db
		$this->db = Zend_Registry::get('connectDB');
	}

	protected $_messageError = null;

	// delete list chat by array of id
	public function deleteListChat($arrId) {
		try {
			$this->db->delete(TOUR_CHAT_TABLE, array($this->TOUR_CHAT_ID.' IN (?)' => $arrId));
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}
	
	// Xoa tour chat
	public function deleteTourChatById($chatId){
		try {
			$this->db->delete(TOUR_CHAT_TABLE,$this->TOUR_CHAT_ID.' = ' . $chatId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}
	
	public function deleteTourChatByUserId($userId){
		try {
			$this->db->delete(TOUR_CHAT_TABLE,$this->USER_ID.' = ' . $userId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}
	
	public function deleteTourChatByTourId($tourId){
		try {
			$this->db->delete(TOUR_CHAT_TABLE,$this->TOUR_ID.' = ' . $tourId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}

	public function getError(){
		return $this->_messageError;
	}
}